//
//  NSString+Extensions.m
//  JQKit
//
//  Created by JQZ on 2017/12/27.
//  Copyright © 2017年 JQZ. All rights reserved.
//

#import "NSString+Extensions.h"
#import "NSString+Trims.h"

@implementation NSString (Extensions)

+ (BOOL)isNilOrEmpty:(NSString *)string {
    return (string == nil ||
            [string isEqual:[NSNull null]] ||
            [string isEqual:nil] ||
            [string length] <= 0);
}

+ (BOOL)isNilOrEmptyOrWhitespace:(NSString *)string {
    return (string == nil ||
            [string isEqual:[NSNull null]] ||
            [string isEqual:nil] ||
            [[string stringByTrimmingWhitespaceAndNewlines] length] <= 0);
}

+ (NSString *)nonNullString:(NSString *)string {
    return (string ? string : [NSString string]);
}

+ (NSString *)nonEmptyStringOrNil:(NSString *)string {
    if ([self isNilOrEmpty:string]) {
        return nil;
    }
    return string;
}

+ (NSString *)nonEmptyTrimmedStringOrNil:(NSString *)string {
    if ([self isNilOrEmptyOrWhitespace:string]){
        return nil;
    }
    return [string stringByTrimmingWhitespaceAndNewlines];
}

- (BOOL)containsString:(NSString *)subString {
    return ([self rangeOfString:subString].location != NSNotFound);
}

- (NSArray *)splitByString:(NSString *)string {
    return [self componentsSeparatedByString:string];
}

@end
